/*
 * @lc app=leetcode.cn id=257 lang=javascript
 *
 * [257] 二叉树的所有路径
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function(root) {
    this.array = []
    const pathsFun = (root) => {
        if (root.right || root.left) {
            if (root.right) {
                root.right.val = root.val + '->' + root.right.val
                pathsFun(root.right)
            }
            if (root.left) {
                root.left.val = root.val + '->' + root.left.val
                pathsFun(root.left)
            }
        } else {
            this.array.push(root.val + '')
        }
    }
    pathsFun(root)
    return this.array
};
// @lc code=end

